package com.cj.webapp.common.utils.http;


import com.alibaba.fastjson.JSON;
import com.cj.webapp.account.pojo.ConstantParamter;
import com.cj.webapp.account.pojo.InvestBdDto;
import com.cj.webapp.account.pojo.MarketTicketDto;
import com.cj.webapp.account.pojo.MemberInfo;
import com.cj.webapp.common.sign.SignVerifyHandle;
import com.cj.webapp.common.utils.HFJsonUtil;
import com.cj.webapp.common.utils.MapDetail;
import com.cj.webapp.common.utils.UtilDatetime;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.*;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.*;


/**
  * 无视Https证书是否正确的Java Http Client
  *
  *
  * @author wz
  *
  * @create 2012.8.17
  * @version 1.0
  */
public class HttpsUtil {

 private static final Logger logger = LoggerFactory.getLogger(HttpsUtil.class);

 //private static ISignVerify signVerify = (ISignVerify) SpringContextUtils.getBeanByClass(ISignVerify.class);

 private static SignVerifyHandle signVerifyHandle=new SignVerifyHandle();


 /**
  * 忽视证书HostName
  */
 private static HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() {
     public boolean verify(String s, SSLSession sslsession) {
         logger.warn("WARNING: Hostname is not matched for cert.");
         return true;
     }
 };

  /**
  * Ignore Certification
  */
 private static TrustManager ignoreCertificationTrustManger = new X509TrustManager() {

     private X509Certificate[] certificates;

     public void checkClientTrusted(X509Certificate certificates[],
             String authType) throws CertificateException {
         if (this.certificates == null) {
             this.certificates = certificates;
             logger.info("init at checkClientTrusted");
         }
     }


     public void checkServerTrusted(X509Certificate[] ax509certificate,
             String s) throws CertificateException {
         if (this.certificates == null) {
             this.certificates = ax509certificate;
             logger.info("init at checkServerTrusted");
         }

     }


     public X509Certificate[] getAcceptedIssuers() {
         // TODO Auto-generated method stub
         return null;
     }
 };


 public static String post(String urlString,String postData) throws Exception {

     ByteArrayOutputStream buffer = new ByteArrayOutputStream(512);
     String result = "";
     HttpsURLConnection connection =null;
     DataOutputStream out =null;
     BufferedReader reader =null;
     try {
         URL url = new URL(null,urlString,new sun.net.www.protocol.https.Handler());

         /*
          * use ignore host name verifier
          */
         HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
         connection = (HttpsURLConnection) url.openConnection();


         // Prepare SSL Context
         TrustManager[] tm = { ignoreCertificationTrustManger };
         SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
         sslContext.init(null, tm, new java.security.SecureRandom());


         // 从上述SSLContext对象中得到SSLSocketFactory对象
         SSLSocketFactory ssf = sslContext.getSocketFactory();
         connection.setSSLSocketFactory(ssf);

         connection.setDoOutput(true);
         connection.setDoInput(true);
         connection.setRequestMethod("POST");
         connection.setUseCaches(false);
         connection.setInstanceFollowRedirects(true);

         connection.setRequestProperty("Content-Type",
         "application/x-www-form-urlencoded");
//            connection.setRequestProperty("Content-Type",
//                    "application/json");

         connection.connect();
         out = new DataOutputStream(connection.getOutputStream());

         out.write(postData.getBytes("UTF-8"));
         out.flush();
         out.close(); // flush and close
         int rc = connection.getResponseCode();
         if (rc == 200) {
             reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
             String line;
             while ((line = reader.readLine()) != null) {
                 result += line;
             }
             reader.close();
             connection.disconnect();
         }
     }catch (IOException io) {
         io.printStackTrace();
     } catch (Exception ex) {
         ex.printStackTrace();
     }finally {
         if( null != out){
             out.close();
         }
         if( null != reader){
             reader.close();
         }
         if( null != connection){
             connection.disconnect();
         }
     }
     return result;
 }

    /**
     * post提交方式
     */
    public static  String doPost(String urlString,String postData){
        String result=null;
        try {
            HttpClient httpClient=new DefaultHttpClient();
            HttpPost requestPost=new HttpPost(urlString);
            requestPost.addHeader("Content-type","application/json; charset=utf-8");
            requestPost.setHeader("Accept", "application/json");

                    /*List<NameValuePair> list=new ArrayList<NameValuePair>();
                    list.add(new BasicNameValuePair("postData", postData));*/

            requestPost.setEntity(new StringEntity(postData,"UTF-8"));
            HttpResponse response = httpClient.execute(requestPost);

            if(response.getStatusLine().getStatusCode()==200){
                HttpEntity entity = response.getEntity();
                result= EntityUtils.toString(entity,"utf-8");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 对私 发送报文 个人
     * @param
     * @return
     */
    public String  sendPersonPri(Map<String,Object> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "011"+df.format(new Date()));//请求流水(贯穿整个请求返回)

        // body
        jsonbody.put("custNm", "王招");//用户姓名
        jsonbody.put("idType", "01");//证件类型
        jsonbody.put("idNo", "411503199305262114");//证件号码
        jsonbody.put("platfmCustId", "01");//客户所在平台ID
        jsonbody.put("channelCode", "010110");//渠道编号(非必填)
        jsonbody.put("phone", "17633719166");//联系人手机号
        jsonbody.put("email","1761160419@qq.com");//邮箱
        jsonbody.put("province","河南省");//省份
        jsonbody.put("city","信阳市");//城市
        jsonbody.put("role","0");//角色 0 投资人 1 融资人
        jsonbody.put("sex","1");//性别（0,1）
        jsonbody.put("birthDt", "1993-08-16");//出生年月日
        jsonbody.put("inviteCd","9999");//邀请码
        jsonbody.put("nickNm", "阿招");//昵称
        jsonbody.put("wechatnum", "Sunny-zhaozhao");//微信号
        jsonbody.put("source", "PC");//注册渠道（微信/PC）
        jsonbody.put("bankAccNo","6212261707000285071");//银行卡号
        jsonbody.put("bankNm", "中国工商银行");//银行名称
        jsonbody.put("bankBranchNm","上海浦东新区支行");//银行所在支行名称
        jsonbody.put("bankProv", "河南省");//银行所在省份
        jsonbody.put("bankCity","平顶山市");//银行所在城市
        jsonbody.put("bankCardOfMobile","17633719166");//银行卡绑定手机号码
        jsonbody.put("cardType","00");//卡类型账户类型：00：对私;01：对公
        jsonbody.put("remark","my heart will go on");//备注

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("对私代付发送报文:"+newjson.toString());
        String res = "";
        try {
           // String urlString = "http://192.168.2.196:8586/gzcw-app/customerController/personRegister.html";
            System.out.println("发送的报文内容====="+newjson.toString());
            res =HttpsUtil.doPost(urlString,newjson.toString());

            System.out.println("成功发送报文！！！！！！！！！！！！");
            logger.info("恒丰对私代付返回报文:"+"||,返回报文："+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }

    /**
     * 对公 发送报文 企业
     * @param
     * @return
     */
    public String  sendEnterPrisePub(Map<String,Object> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "120"+df.format(new Date()));//请求流水(贯穿整个请求返回)

        // body
        jsonbody.put("custNm", "a招");//用户姓名
        jsonbody.put("idType", "06");//证件类型
        jsonbody.put("idNo", "411503199905123325");//证件号码
        jsonbody.put("platfmCustId", "0001");//用户所在平台ID
        jsonbody.put("channelCode", "010110");//渠道编号(非必填)
        jsonbody.put("email","1761160419@qq.com");//邮箱
        jsonbody.put("province","河南省");//省份
        jsonbody.put("city","信阳市");//城市
        jsonbody.put("role","0");//角色 0 投资人 1 融资人
        jsonbody.put("wechatnum", "Sunny-zhaozhao");//微信号
        jsonbody.put("source", "微信");//注册渠道（微信/PC）
        jsonbody.put("orgNo", "92320113MA1UTP1Q1W");//组织机构代码
        jsonbody.put("businessLicense", "EC51543");//营业执照编号
        jsonbody.put("taxNo", "231130011");//税务登记号
        jsonbody.put("cerditCode", "EC552543360");//机构信用代码（机构）
        jsonbody.put("legalNm", "凌永志");//法人姓名（机构）
        jsonbody.put("contact", "凌总");//企业联系人（机构）
        jsonbody.put("phone", "17633719166");//企业联系人手机号
        jsonbody.put("registDt", "2016-08-08");//注册日期
        jsonbody.put("compInfo", "初九数据公司");//公司信息
        jsonbody.put("compBankGround", "很深");//企业背景
        jsonbody.put("compAddres", "上海市陆家嘴");//公司地址
        jsonbody.put("inviteCd", "9999");//邀请码
        jsonbody.put("nickNm", "阿招");//昵称
        jsonbody.put("bankLicense", "812456554");//开户银行许可证号
        jsonbody.put("bankAccNo", "6212261707000285071");//企业对公账户
        jsonbody.put("bankNm", "中国工商");//银行名称
        jsonbody.put("bankCode", "中国工商");//银行名称
        jsonbody.put("bankBranchNm", "平顶山平煤支行");//银行所在支行名称
        jsonbody.put("bankProv", "河南省");//银行所在省份
        jsonbody.put("bankCity", "平顶山市");//银行所在城市
        jsonbody.put("bankCardOfMobile", "17633719166");//银行卡绑定手机号码
        jsonbody.put("cardType", "0");//卡类型（0对公1对私）(详见码值表)
        jsonbody.put("remark", "企业");//备注

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("对私代付发送报文:"+newjson.toString());
        String res = "";
        try {
            // String urlString = "http://192.168.2.196:8586/gzcw-app/customerController/personRegister.html";
            System.out.println("发送的报文内容====="+newjson.toString());
            res =HttpsUtil.doPost(urlString,newjson.toString());

            System.out.println("成功发送报文！！！！！！！！！！！！");
            logger.info("恒丰对私代付返回报文:"+"||,返回报文："+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }


    /**
     * 获取Token 发送报文
     * @param
     * @return
     */
    public String  sendToken(Map<String,Object> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","GET_TOKEN");//接口名称
        jsonhead.put("vipNum", ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+df.format(new Date()));//请求流水(贯穿整个请求返回)
        //jsonhead.put("sessionId",map.get("sessionId"));//sessionId
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号


        // body
        jsonbody.put("custNm", map.get("custNm"));//用户姓名
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//用户所在平台ID
        //jsonbody.put("role", "0");//角色 0 投资人 1 融资人

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("请求token发送报文:"+newjson.toString());
        Map<String,String> mapRes=new HashMap<>();
        String res =null;
        try {
            // String urlString = "http://192.168.2.196:8586/gzcw-app/customerController/personRegister.html";
            res =HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("返回报文内容:"+"||"+res);
            mapRes= HFJsonUtil.getJsonToMap(res);
            res=HttpsUtil.getResultMap(mapRes);

            logger.info("返回token:"+"||"+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }

    /**
     * 获取用户信息 发送报文
     * @param
     * @return
     */
    public List<MemberInfo> sendUserList(Map<String,Object> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","QUERY_CUST_INFO");
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "114"+df.format(new Date()));//请求流水(贯穿整个请求返回)
        jsonhead.put("token",map.get("token"));//token
        jsonhead.put("sessionId",map.get("sessionId"));//sessionId
        jsonhead.put("source",map.get("source"));//sessionId
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号


        // body
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//所在平台该用户ID（用户在普惠家的ID）
        jsonbody.put("role", map.get("role"));//角色

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("获取用户信息发送报文:"+newjson.toString());
        Map<String,String> mapRes=new HashMap<>();
        List<MemberInfo> memberInfoList=new ArrayList<>();
        String res =null;
        try {
            res =HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("获取用户信息返回报文:"+res);
           // net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(res);
            Map<String, String> jsonToMap = HFJsonUtil.getJsonToMap(res);
            Map<String, String> headMap = HFJsonUtil.getJsonToMap(jsonToMap.get("head"));
            if("000000".equals(headMap.get("code"))){
                if(signVerifyHandle.verifySign(ConstantParamter.VIP_NUM,jsonToMap.get("body"), headMap.get("signData"))){
                    memberInfoList = JSONObject.parseArray(HFJsonUtil.getJsonToMap(jsonToMap.get("body")).get("custInfoList"), MemberInfo.class);
                    //MapDetail.resMap.put("role",mapRes.get("role"));
                }else{
                    logger.info("用户信息查询返回信息:验签失败");
                }
            }else{
                logger.info("用户信息查询返回信息message:"+"||"+jsonToMap.get("message"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return  memberInfoList;
    }
    /**
     * 用户银行卡操作 发送报文
     * @param
     * @return
     */
    public String  sendBankMessage(Map<String,Object> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "112"+df.format(new Date()));//请求流水(贯穿整个请求返回)

        // body
        jsonbody.put("platfmCustId", "0001");//所在平台该用户ID（用户在普惠家的ID）
        jsonbody.put("serviceName", "HY");//请求名称（XZ新增银行卡、HY会员充值、TX会员提现、HK会员换卡、XGPAY修改支付密码）

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("对私代付发送报文:"+newjson.toString());
        Map<String,String> mapRes=new HashMap<>();
        String res =null;
        try {
            res =HttpsUtil.doPost(urlString,newjson.toString());
            System.out.println("发送的报文内容====="+newjson.toString());
            System.out.println("返回报文："+res);
            mapRes= HFJsonUtil.getJsonToMap(res);
            res=HttpsUtil.getResultMap(mapRes);

            System.out.println("成功发送报文！！！！！！！！！！！！,返回报文："+mapRes);
            logger.info("恒丰对私代付返回报文:"+"||"+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }

    /**
     * 拿到token值
     * @param map
     * @return
     */
    public static String getResultMap(Map<String,String> map){
        String tokeyString=null;
        Map<String, String> headMap = HFJsonUtil.getJsonToMap(map.get("head"));
        //HFJsonUtil.getJsonToMap(map.get("body"));
        if(headMap!=null&&headMap.containsKey("code")){
            if(headMap.get("code").equals("000000")){
                if(signVerifyHandle.verifySign(ConstantParamter.VIP_NUM, map.get("body"), headMap.get("signData"))){
                    Map<String, String> data= HFJsonUtil.getJsonToMap(map.get("body"));
                    tokeyString=data.get("token");
                }else{
                    logger.info("token验签结果:验签失败");
                }
            }else {
                logger.info("token信息查询返回信息:"+"||"+headMap.get("message"));
            }
        }
        return tokeyString;
    }


    /**
     * 获取认购标的列表发送报文
     * @param
     * @return
     */
    public List<InvestBdDto>   sendInvestBdList(Map<String,Object> map,String urlString){
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);
        // head
        jsonhead.put("serviceName","GET_INVEST_BDLIST");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("pageSize", 10);//每页条数(默认10条，最大值为50，超过50算作50)
        jsonbody.put("pageNo", 0);//页码


        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("请求认购标的列表发送报文:"+newjson.toString());
        List<InvestBdDto> listRes=new ArrayList<>();
        String res =null;
        try {
            res = HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("请求认购标的列表返回报文内容:"+"||"+res);
            Map<String, String> jsonToMap = HFJsonUtil.getJsonToMap(res);
            Map<String, String> headMap = HFJsonUtil.getJsonToMap(jsonToMap.get("head"));
            if("000000".equals(headMap.get("code"))){
                if(signVerifyHandle.verifySign(ConstantParamter.VIP_NUM,jsonToMap.get("body"), headMap.get("signData"))){
                    listRes= JSON.parseArray(HFJsonUtil.getJsonToMap(jsonToMap.get("body")).get("bdInfoList"),InvestBdDto.class);
                }else{
                    logger.info("请求认购标的列表:验签失败");
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("请求认购标的列表失败");
        }
        return  listRes;
    }

    /**
     * 获取标的详情
     * @param
     * @return
     */
    public Map<String,String>  sendInvestBdDetail(Map<String,Object> map,String urlString){
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);
        // head
        jsonhead.put("serviceName","GET_INVEST_BDDETAIL");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("bdNo",map.get("bdNo"));//标的编号


        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("获取标的详情发送报文:"+newjson.toString());
        Map<String,String> mapRes=new HashMap<>();
        String res =null;
        try {
            res = HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("获取标的详情返回报文内容:"+"||"+res);
            Map<String, String> jsonToMap = HFJsonUtil.getJsonToMap(res);
            Map<String, String> headMap = HFJsonUtil.getJsonToMap(jsonToMap.get("head"));
            if("000000".equals(headMap.get("code"))){
                if(signVerifyHandle.verifySign(ConstantParamter.VIP_NUM,jsonToMap.get("body"), headMap.get("signData"))){
                    mapRes= HFJsonUtil.getJsonToMap(jsonToMap.get("body"));
                }else{
                    logger.info("请求认购标的详情:验签失败");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("请求认购标的详情失败");
        }
        return  mapRes;
    }

    /**
     * 用户可用营销券查询(合作平台提供)
     * @param
     * @return
     */
    public String  sendMarketTicketDetail(Map<String,String> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","QUERY_MARKTICKET");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("bdNo",map.get("bdNo"));//产品代码
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//合作平台用户编号
        jsonbody.put("amount", map.get("amount"));//投资金额
        List<MarketTicketDto> myList=new ArrayList<>();
        MarketTicketDto dto=new MarketTicketDto();
        dto.setMarkTicketValue(BigDecimal.valueOf(200));
        dto.setMarkTicketId("100092");
        dto.setMarkType("0");//0抵用券/红包
        myList.add(dto);
        jsonbody.put("markTicketList", myList);//营销明细(包含红包，抵用券，加息券)

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));

        return  newjson.toJSONString();
    }
    /**
     * 用户可用营销券查询(合作平台提供)
     * @param
     * @return
     */
    public String  sendMarketTicketDetail2(Map<String,String> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","QUERY_MARKTICKET");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("bdNo",map.get("bdNo"));//产品代码
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//合作平台用户编号
        jsonbody.put("amount", map.get("amount"));//投资金额
        List<MarketTicketDto> myList=new ArrayList<>();
        MarketTicketDto dto=new MarketTicketDto();
        dto.setMarkTicketValue(BigDecimal.valueOf(200));
        dto.setMarkTicketId("100091");
        dto.setMarkType("1");//1加息券
        myList.add(dto);
        jsonbody.put("markTicketList", myList);//营销明细(包含红包，抵用券，加息券)

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("用户可用营销券查询发送报文:"+newjson.toString());

        return  newjson.toJSONString();
    }
    /**
     * 用户可用营销券查询(合作平台提供)
     * @param
     * @return
     */
    public String  sendMarketTicketDetail3(Map<String,String> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","QUERY_MARKTICKET");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("bdNo",map.get("bdNo"));//产品代码
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//合作平台用户编号
        jsonbody.put("amount", map.get("amount"));//投资金额

        List<MarketTicketDto> myList=new ArrayList<>();
        MarketTicketDto dto=new MarketTicketDto();
        dto.setMarkTicketValue(BigDecimal.valueOf(200));
        dto.setMarkTicketId("10009");
        dto.setMarkType("0");
        myList.add(dto);
        MarketTicketDto dto2=new MarketTicketDto();
        dto2.setMarkTicketValue(BigDecimal.valueOf(300.00));
        dto2.setMarkTicketId("10009");
        dto2.setMarkType("1");
        myList.add(dto2);
        jsonbody.put("markTicketList", myList);//营销明细(包含红包，抵用券，加息券)

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("用户可用营销券查询发送报文:"+newjson.toString());
        String res = "";
        try {
            res =HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("用户可用营销券查询返回报文:"+"||,返回报文："+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }

    /**
     * 投资使用营销券校验(合作平台提供)
     * @param
     * @return
     */
    public String  sendMarketTicketUsing(Map<String,String> map,String urlString){
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonData = new JSONObject(true);
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);

        // head
        jsonhead.put("serviceName","CHECK_MARKTICKET");//接口
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+UtilDatetime.getDatetimeString());//请求流水(贯穿整个请求返回)
        //jsonhead.put("token", map.get("token"));//token值
        jsonhead.put("source",map.get("source"));//source
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        // body
        jsonbody.put("bdNo",map.get("bdNo"));//产品代码
        jsonbody.put("platfmCustId", map.get("platfmCustId"));//合作平台用户编号
        jsonbody.put("status", "SUCCESS");//投资金额

        jsonData.put("head", jsonhead);
        jsonData.put("body", jsonbody);

        JSONObject newjson = new JSONObject();
        String b = null;
        try {
            b = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonData.getString("body"));
            jsonData.getJSONObject("head").put("signData", b);

        } catch (Exception e) {
            e.printStackTrace();
        }
        newjson.put("head", jsonData.getJSONObject("head"));
        newjson.put("body", jsonData.getJSONObject("body"));
        logger.info("投资使用营销券校验发送报文:"+newjson.toString());
        String res = "";
        try {
            res =HttpsUtil.doPost(urlString,newjson.toString());
            logger.info("投资使用营销券校验返回报文:"+"||,返回报文："+res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }



    public static void main(String... args) {
        //个人
        // String urlString = "http://192.168.2.169:8080/gzcw-app/customerController/personRegister.html";
        //企业
        //String urlString = "http://192.168.2.196:8586/gzcw-app/customerController/enterpriseRegister.html";

        //token发送报文
       // String urlString = "http://192.168.2.169:8080/gzcw-app/sysController/getToken.html";

       //用户信息查询
       //String urlString = "http://192.168.2.152:8020/gzcw-app/customerController/queryCustInfo.html";

        //用户银行卡操作
        String urlBankString="http://192.168.2.196:8586/gzcw-app/accountController/bankManager";

        HttpsUtil httpsUtil=new HttpsUtil();
        //httpsUtil.sendPersonPri(new HashMap<>(),urlString);
         //httpsUtil.sendEnterPrisePub(new HashMap<>(),urlString);
       // httpsUtil.sendToken(new HashMap<>(),urlString);
        //httpsUtil.sendUserList(new HashMap<>(),urlString);
       // httpsUtil.sendBankMessage(new HashMap<>(),urlBankString);
    }


}